package com.mj.entity;

import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.annotation.Resource;
import javax.annotation.Resources;

@Data
//@Component通用组件
//@Controller控制器
//@Service业务
@Repository//用component注解类,Controller和Service以及Repository（数据库层）也可以注解
@Lazy(true)
public class Book {
    @Value("111")//用value注解值
    private int id;
    @Value("百年孤独")
    private String name;
    //注解可以有多个初始化和销毁方法，而配置则不可以
    //@Resource(name = "teacher")
    @Autowired//这里的Resource和autowired效果一样，都相当于自动装配,auto是默认根据byname进行自动装配，如果没有找到，再根据bytype进行自动装配
    public Teacher teacher;
    public Book(){
        System.out.println("构造方法");
    }
    @PreDestroy
    public void closea(){
        System.out.println("closea");
    }
    @PreDestroy
    public void closeb(){
        System.out.println("closeb");
    }
    @PreDestroy
    public void closec(){
        System.out.println("closec");
    }
    @PostConstruct
    public void inita(){
        System.out.println("inita");
    }
    @PostConstruct
    public void initb(){
        System.out.println("initb");
    }
    @PostConstruct
    public void initc(){
        System.out.println("initc");
    }
}
